package pers.qianyu.month_202102.date_20210227;

/**
 * 1299. 将每个元素替换为右侧最大元素
 * https://leetcode-cn.com/problems/replace-elements-with-greatest-element-on-right-side/
 *
 * @author mizzle rain
 * @date 2021-02-27 17:01
 */
public class ReplaceElements {
    public int[] replaceElements(int[] arr) {
        int max = -1;
        int n = arr.length;
        for (int i = n - 1; i >= 0; i--) {
            int t = arr[i];
            arr[i] = max;
            max = Math.max(max, t);
        }
        return arr;
    }
}
